package com.xing.util;

import java.util.List;

public class QueryBuilder {

	public static final String LIKE = "like";
	public static final String EQUAL = "=";
	
	public static void buildQueryCondition(String query, String filedName,
			String condition, List<String> result) {
		if (!Util.isEmpty(query)) {
			
			if (condition.equals(LIKE)) {
				result.add(filedName + " like '%" + Util.likeEscape(query) + "%'");
			}
			if (condition.equals(EQUAL)) {
				result.add(filedName + " = '" + Util.sqlEscape(query) + "'");
			}
		}
	}
	
	public static void buildTimeQueryCondition(String start, String end,
			String filedName, List<String> result) {
		
		if (!Util.isEmpty(start) && !Util.isEmpty(end)) {
			result.add(filedName + " between '" + start + "' and '" + end + "'");
		} else if (!Util.isEmpty(start)) {
			result.add(filedName + " >= '" + start + "'");
		} else if (!Util.isEmpty(end)) {
			result.add(filedName + " <= '" + end + "'");
		}
		
	}
}
